import axios from "axios";
import service from "@/config/index";

const URLS = {
  CUSTOMER_ADD: `${service.serviceQuotation}/template/customer`,
  INSPECT_CARRIER: `${service.serviceQuotation}/template/carrier/validate`,
  INSPECT_CUSTOMER: `${service.serviceQuotation}/template/customer/validate`,
  CARRIER_ADD: `${service.serviceQuotation}/template/carrier`,
  SEND: `${service.serviceQuotation}/template/submit`,

  CUSTOMER_SEND: `${service.serviceQuotation}/template/customer/submit`,
  CARRIER_SEND: `${service.serviceQuotation}/template/carrier/submit`,

  RECALL: `${service.serviceQuotation}/template/recall`,
  CLOSE_RECALL: `${service.serviceQuotation}/template/close/recall`
};

export default {
  // 发货方保存
  addCustomer (params) {
    return axios.post(URLS.CUSTOMER_ADD, params);
  },
  // 检查发货方
  verifyCustomer (params) {
    return axios.post(URLS.INSPECT_CUSTOMER, params);
  },
  // 检查承运方
  verifyCarrier (params) {
    return axios.post(URLS.INSPECT_CARRIER, params);
  },
  // 承运方保存
  carrierAdd (params) {
    return axios.post(URLS.CARRIER_ADD, params);
  },
  // 发货方发送合约  老接口
  send (params) {
    return axios.put(URLS.SEND, params);
  },
  // 发货方发送合约  新接口
  customerSend (params) {
    return axios.post(URLS.CUSTOMER_SEND, params);
  },
  // 发货方发送合约  新接口
  carrierSend (params) {
    return axios.post(URLS.CARRIER_SEND, params);
  },
  // 待审核
  recalls (params) {
    return axios.put(URLS.RECALL, params);
  },
  // 关闭待审核
  closeRecalls (params) {
    return axios.put(URLS.CLOSE_RECALL, params);
  },
  // 获取合约报价详情
  getTemplate (templateId) {
    return axios.get(`${service.serviceQuotation}/template/${templateId}`);
  },
  // 合约报价单 合约关闭
  contractClose (params) {
    return axios.put(
      `${service.serviceQuotation}/template/close/submit`,
      params
    );
  },
  // 约报价单 关闭合约
  closeCustomer (params) {
    return axios.put(`${service.serviceQuotation}/template/close`, params);
  },

  // 合约报价 取消关闭合约
  closeCancel (params) {
    return axios.put(
      `${service.serviceQuotation}/template/close/cancel`,
      params
    );
  },

  // 更新发货方合约
  updateCustomer (templateId, data) {
    return axios.put(
      `${service.serviceQuotation}/template/customer/${templateId}`,
      data
    );
  },

  // 更新承运方合约
  updateCarrier (templateId, data) {
    return axios.put(
      `${service.serviceQuotation}/template/carrier/${templateId}`,
      data
    );
  },

  // 同意
  templateAgree (params) {
    return axios.put(`${service.serviceQuotation}/template/agree`, params);
  },
  // 拒绝
  templateRefuse (params) {
    return axios.put(`${service.serviceQuotation}/template/reject`, params);
  },
  // 同意关闭
  templateCloseAgree (params) {
    return axios.put(
      `${service.serviceQuotation}/template/close/agree`,
      params
    );
  },
  // 同意拒绝
  templateCloseRefuse (params) {
    return axios.put(
      `${service.serviceQuotation}/template/close/reject`,
      params
    );
  },

  // 获取报价详情
  getQuotation (quotationId) {
    return axios.get(`${service.serviceQuotation}/${quotationId}`);
  },
  // 获取运单有效报价详情
  getValidWaybillQuotation (waybillId) {
    return axios.get(`${service.serviceQuotation}/waybill/${waybillId}`);
  },
  // 获取合单有效报价详情
  getValidCombineQuotation (combineId) {
    return axios.get(`${service.serviceQuotation}/combined/waybill/${combineId}`);
  },
  // 获取运费明细（费用）
  getPrice (quotationId) {
    return axios.get(`${service.serviceQuotation}/getFees/${quotationId}`);
  },
  // 创建运单报价（保存）
  createQuotation (data) {
    return axios.post(`${service.serviceQuotation}`, data);
  },
  // 修改报价详情
  updateQuotation (quotationId, data) {
    return axios.put(`${service.serviceQuotation}/${quotationId}`, data);
  },
  // 同意报价
  agree (data) {
    return axios.put(`${service.serviceQuotation}/agree`, data);
  },
  // 议价
  bargain (data) {
    return axios.put(`${service.serviceQuotation}/bargain`, data);
  },
  // 撤回报价
  recall (data) {
    return axios.put(`${service.serviceQuotation}/recall`, data);
  },
  // 拒绝报价
  refuse (data) {
    return axios.put(`${service.serviceQuotation}/reject`, data);
  },
  // 发送报价
  sendQuotation (data) {
    return axios.put(`${service.serviceQuotation}/submit`, data);
  },
  // 报价前置效验
  validateQuote (subjectId) {
    return axios.get(`${service.serviceQuotation}/validate/${subjectId}`);
  },
  validateCheckQuotation (subjectId) {
    return axios.get(`${service.serviceQuotation}/check/${subjectId}`);
  },
  // 补充报价
  addSurcharge (data) {
    return axios.post(`${service.serviceQuotation}/addSurcharge`, data);
  },
  // 关闭报价单
  discard (data) {
    return axios.put(`${service.serviceQuotation}/discard`, data);
  },
  // 关闭报价单
  close (data) {
    return axios.put(`${service.serviceQuotation}/close`, data);
  },
  // 合单有效报价
  onebillValidFee (combineId) {
    return axios.get(`${service.serviceQuotation}/combined/waybill/${combineId}`);
  },
  // 报价查询是否能够匹配合约
  isQuoteMatch (data) {
    return axios.post(`${service.serviceQuotation}/template/match`, data);
  },
  // 报价查询是否能够匹配合约
  isQuoteRefresh (data) {
    return axios.post(`${service.serviceQuotation}/template/refresh`, data);
  },
  // 报价确认合约匹配
  quoteMatch (data) {
    return axios.post(`${service.serviceQuotation}/match`, data);
  },
  // 合约匹配明细
  getMatch (matchId) {
    return axios.get(`${service.serviceQuotation}/template/match/${matchId}`);
  },
  // 上传图片通用接口
  readExcel (data) {
    let response = axios.post(`${service.serviceQuotation}/excel/read`, data);
    return response;
  }
};
